﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ApiBetaSeries.Model;
using ApiBetaSeries.Utils;
using System.Xml;

namespace ApiBetaSeries.Factories
{
    public class SubtitleFactory
    {
        /// <summary>
        /// Create a new subtitle from xml
        /// </summary>
        /// <param name="e">An XmlNode</param>
        /// <returns>A Subtitle</returns>
        [ApiBetaSeries.Version.ApiMethod(true, "shows/episodes", "planning/member", "members/episodes", "planning/general", "subtitles/last", "subtitles/show")]
        public static ISubtitle CreateSubtitle(XmlNode e)
        {
            ISubtitle subtitle = new Subtitle();
            subtitle.Show = UtilsXML.GetStringValue(e, "title");
            subtitle.Season = UtilsXML.GetIntValue(e, "season");
            subtitle.Episode = UtilsXML.GetIntValue(e, "episode");
            subtitle.Language = UtilsEnum.StringToSubtitleLanguage(UtilsXML.GetStringValue(e, "language"));
            subtitle.Source = UtilsXML.GetStringValue(e, "source");
            subtitle.FileName = UtilsXML.GetStringValue(e, "filename");
            // File or FileName...
            if (string.IsNullOrEmpty(subtitle.FileName))
            {
                subtitle.FileName = UtilsXML.GetStringValue(e, "file");
            }
            subtitle.Url = UtilsXML.GetStringValue(e, "url");
            subtitle.Quality = UtilsXML.GetIntValue(e, "quality");

            return subtitle;
        }

        /// <summary>
        /// Create a new Subtitle
        /// </summary>
        /// <returns>A new subtitle</returns>
        public static ISubtitle CreateSubtitle()
        {
            return new Subtitle();
        }
    }
}
